import {
    AUTH_GET_PERMISSIONS,
    AUTH_LOGIN,
    AUTH_LOGOUT,
    AUTH_ERROR,
    AUTH_CHECK,
} from 'react-admin'; // eslint-disable-line import/no-unresolved

// Authenticatd by default
export default (type) => {
    if (type === AUTH_LOGIN) {
        const request = new Request('https://oapi.dingtalk.com/sns/gettoken?appid=dingoagwdxvlqczpib6n2h&appsecret=VS0rAHm6zVepv4DcFLrO20iMcMvMffSQTvGkpaw6BnEPHq-Y5b8Gi10N1T1uU6PI', {
            method: 'GET',
            // body: JSON.stringify({username, password}),
            headers: new Headers({'Content-Type': 'application/json'}),
        });
        return fetch(request)
            .then(response => {
                if (response.status < 200 || response.status >= 300) {
                    throw new Error(response.statusText);
                }
                return response.json();
            })
            .then(({access_token}) => {
                localStorage.setItem('token', access_token);
            });
    }
    return Promise.resolve();
};

